from tqsdk import TqApi, TqAuth, TqAccount
import time
tqacc = TqAccount("H徽商期货", "155831", "alibaba999")
api = TqApi(account=tqacc, auth=TqAuth("szlwy68", "alibaba999"),web_gui=True)


myacc=api.get_account()
#print(myacc.available)

#下面这种查询账户持仓情况的方法不是很好，还有更好的办法吗？
###########################################
# mypos=api.get_position()
# #print(mypos)
# x=[x for x in mypos]
# #print(x)

# for i in x:
#     pos=api.get_position(i)
#     print(i,pos.pos,pos.float_profit,pos.last_price)
###########################################

position=api.get_position()
print(position)
for k,v in position.items(): # k是品种代码，v是position对象
    print(str(k),str(v.pos),str(v.float_profit)) 

print("while out 当前账户可用资金：",myacc.available)

t=0
while True: 
    api.wait_update(deadline=0.5)
    #print("登录成功")
    if(time.time()-t>10):
        print(t)
        t=time.time()
        print("当前账户可用资金：",myacc.available)
        print("当前账户总资产：",myacc.balance)
        

